package com.linkhouse.interfaces;

import com.alibaba.fastjson.JSONObject;
import com.linkhouse.domain.po.NavigationParameters;
import com.linkhouse.domain.po.TbNewRoom;
import com.linkhouse.mapper.TbNewRoomMapper;
import com.linkhouse.util.RealIpUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("newRoom")
@RefreshScope //开启自动刷新配置
public class TbNewRoomInterfaces {
    @Autowired
    private TbNewRoomMapper tbNewRoomMapper;
    @Autowired
    private RestTemplate    restTemplate;

    //用户位置
    @GetMapping
    public List<TbNewRoom> query(HttpServletRequest request,Long smallAreaId) {
        String ipAddr = RealIpUtils.getIpAddr(request);
        System.err.println(ipAddr);
        String sn = "CTFkxmMoAXXoMAG342l7x10d46RtGm7T";
        String ak = "YwQcogVo3CVUj4ukQxcxEpaEaKVLnXWP";
        String url = "http://api.map.baidu.com/location/ip?ak="+ak+"&ip=103.46.128.49&coor=bd09ll";
        String forEntity = restTemplate.getForObject(url, String.class);
        NavigationParameters navigationParameters = JSONObject.parseObject(forEntity, NavigationParameters.class);
        System.err.println(navigationParameters.toString());

        List<TbNewRoom> tbNewRooms = tbNewRoomMapper.selectList(null);
        HashMap<String ,Object> map = new HashMap<>();
        /*更具房源小区small_area_id查询*/
        smallAreaId = 2L;
        map.put("small_area_name",smallAreaId);
        List<TbNewRoom> tbNewRooms1 = tbNewRoomMapper.selectByMap(map);

        return tbNewRooms1;
    }
}


